﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Maticsoft.Common;
using System.Text;

namespace Lawyer.Web.Admin
{
    public partial class admin_file : System.Web.UI.Page
    {
        Lawyer.BLL.FileInfo bll = new Lawyer.BLL.FileInfo();
        public string ArchiveID = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                ArchiveID = Request.QueryString["id"].ToString();
            }
            catch { }
            //btnDelete.Attributes.Add("onclick", "return confirm(\"你确认要删除吗？\")");
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }

        public void BindData()
        {
            DataSet ds = new DataSet();
            string strWhere = "";
            if (ArchiveID != "")
            {
                strWhere = "ArchiveID = '"+ArchiveID+"'";
            }
            //string strWhere = "LawyerID = '" + Session["UserName"].ToString() + "'";
            ds = bll.GetList(strWhere);
            fileList.DataSource = ds;
            fileList.DataBind();
            if (fileList.Rows.Count != 0)
            {
                fileList.HeaderRow.TableSection = TableRowSection.TableHeader;
            }
            btnDelete.Visible = false;
        }

        private string GetSelIDlist()
        {
            string idlist = "";
            bool BxsChkd = false;
            for (int i = 0; i < fileList.Rows.Count; i++)
            {
                CheckBox ChkBxItem = (CheckBox)fileList.Rows[i].FindControl("DeleteThis");
                if (ChkBxItem != null && ChkBxItem.Checked)
                {
                    BxsChkd = true;
                    //#warning 代码生成警告：请检查确认Cells的列索引是否正确

                    if (fileList.DataKeys[i].Value != null)
                    {
                        if (idlist.Length == 0)
                        {
                            idlist = idlist + "'" + fileList.DataKeys[i].Value.ToString() + "',";
                        }
                        else
                        {
                            idlist = idlist + "'" + fileList.DataKeys[i].Value.ToString() + "',";
                        }
                    }
                }
            }
            if (BxsChkd)
            {
                idlist = idlist.Substring(0, idlist.LastIndexOf(","));
            }
            return idlist;
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            //string idlist = GetSelIDlist();
            //if (idlist.Trim().Length == 0)
            //    return;
            //bll.DeleteFiles(idlist);
            //bll.DeleteList(idlist);
            //BindData();
        }

        protected void fileList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            { }
        }

        protected void fileList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            fileList.PageIndex = e.NewPageIndex;
            BindData();
        }
    }
}
